<template>
  <el-dialog
    :title="title"
    :visible.sync="isShow"
    :close-on-click-modal="false"
    width="580px"
    @close="resetDialog"
    append-to-body
  >
    <el-form size="small" :show-message="false">
      <el-row>
        <el-col :span="24">
        <el-form-item label="执行情况：">
          <el-select v-model="form.execution" placeholder="请选择" style="width:100%;">
          <el-option v-for="(item,index) in initData.executions" :key="index" :label="item.name" :value="item.id"></el-option>
        </el-select>
        </el-form-item>
        </el-col>
        <el-col :span="24">
        <el-form-item label="强化管控建议：">
          <el-input v-model="form.measures_advanced" placeholder="请输入" type="textarea" :autosize="{minRows:4,maxRows: 6}"/>
        </el-form-item>
        </el-col>
        <el-col :span="24" v-if="!userInfo.is_region_user">
        <el-form-item label="监控记录：">
          <el-input v-model="form.records" placeholder="请输入" type="textarea" :autosize="{minRows:4,maxRows: 6}"/>
        </el-form-item>
        </el-col>
      </el-row>
    </el-form>
  <div slot="footer" class="dialog-footer">
      <el-button size="small" @click="isShow = false">取 消</el-button>
      <el-button :loading="btnLoading" size="small" type="primary" @click="submitForm">保 存</el-button>
    </div>
  </el-dialog>
</template>

<script>
export default {
  data(){
    return{
      title: '',
      isShow: false,
      btnLoading: false,
      row: {},
      form:{
        editor: null,
        execution: null,
        measures_advanced: null,
        records: null
      },
      defaultForm: {},
      checkForm: null,
      initData:{},
      userInfo:{},
    }
  },
  created(){
    this.defaultForm = JSON.parse(JSON.stringify(this.form));
    this.userInfo = this.$store.getters.currentUserInfo;
  },
  methods:{
    init(row){
      console.log(row);
      this.row = row;
      this.title = row.name;
      this.$util.resetForm(this.form, row);
      this.checkForm = JSON.parse(JSON.stringify(this.form));
      this.initData = JSON.parse(JSON.stringify(this.$parent.$parent.initData));
      this.initData.executions.shift();
      this.isShow = true;
    },
    resetDialog(){
      this.form = JSON.parse(JSON.stringify(this.defaultForm));
      this.btnLoading = false;
    },
    submitForm(){
      if(JSON.stringify(this.form) == JSON.stringify(this.checkForm)){
        this.isShow = false;
        return;
      }
      this.form.editor = this.$store.getters.currentUser;
      let params = this.$util.filterNull(this.form);
      this.btnLoading = true;      
      this.$request('post', '/stations/pollute_incidence_list_upd?rec_id='+this.row.rec_id, params, (data,msg) => {
        if(data.msg == '更新成功'){
          this.isShow = false;
          this.$message.success(data.msg);
          this.$emit('confirm');
        }else{
          this.$message.error(data.msg);
        }        
        this.btnLoading = false;
      }, msg => {
        this.btnLoading = false;
      })
    }
  }
}
</script>

<style>

</style>